﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ConstructorTest", Namespace="http://kis.x-road.eu/", Target=typeof(ConstructorTest))]
    public class ConstructorTestSerializer : global::Kis.Xroad.Eu.ConstructorTestExtensionSerializer {
        
        public ConstructorTestSerializer(ConstructorTest clazz) : 
                base(clazz) {
        }
        
        protected new ConstructorTest clazz {
            get {
                return ((ConstructorTest)(base.clazz));
            }
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.CTProp!=null) {
                Writer.WriteStartElement("CTProp");
                Writer.WriteString(clazz.CTProp.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.CTProp1!=null) {
                Writer.WriteStartElement("CTProp1");
                Writer.WriteString(clazz.CTProp1.ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("CTProp2");
            if (clazz.CTProp2!=null) {
                Writer.WriteString(clazz.CTProp2.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : CTProp2");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("CTProp3");
            if (clazz.CTProp3!=null) {
                Writer.WriteString(clazz.CTProp3.ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="CTProp") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ConstructorTest>CTProp");
                }
                clazz.CTProp = new global::Kis.Xroad.Eu.PositiveCelcius(Reader.ReadElementString("CTProp"));
            }
            if (Reader.LocalName=="CTProp1") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.CTProp1 = new global::Kis.Xroad.Eu.PositiveCelcius(Reader.ReadElementString("CTProp1"));
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="CTProp2") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ConstructorTest>CTProp2");
                }
                clazz.CTProp2 = new global::Kis.Xroad.Eu.PositiveCelcius(Reader.ReadElementString("CTProp2"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ConstructorTest>CTProp2", Reader.LocalName);
            }
            if (Reader.LocalName=="CTProp3") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.CTProp3 = new global::Kis.Xroad.Eu.PositiveCelcius(Reader.ReadElementString("CTProp3"));
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ConstructorTest>CTProp3", Reader.LocalName);
            }
        }
    }
}
